$(document).ready(function() {
	//1.插件初始化
	//初始化mui
	mui.init();

	//监听返回键
	mui.plusReady(function() {
		//首页返回键处理
		//处理逻辑：1秒内，连续两次按返回键，则退出应用；
		var first = null;
		plus.key.addEventListener('backbutton', function() {
			//首次按键，提示‘再按一次退出应用’
			if (!first) {
				first = new Date().getTime();
				mui.toast('再按一次退出应用');
				setTimeout(function() {
					first = null;
				}, 1000);
			} else {
				if (new Date().getTime() - first < 1000) {
					plus.runtime.quit();
				}
			}
		}, false);
	});

	//加载swiper
	var swiper = new Swiper('.swiper-container', {
		effect: 'cube',
		touchMoveStopPropagation: false,
		cube: {
			shadow: false,
			slideShadows: false
		},
		onReachBeginning: function(swiper) {
			$('#page-view').attr('src', 'img/icon/main_page_one.png');
		},
		onReachEnd: function(swiper) {
			$('#page-view').attr('src', 'img/icon/main_page_two.png');
		}
	});

	//2.主要样式
	//内容区事件监听
	$('.main-block').each(function() {
		$(this).bind({
			'vmousedown': function() {
				$(this).addClass("block-onmousedown");
			},
			'vmouseup': function() {
				$(this).removeClass("block-onmousedown");
			}
		})
	})

	$('.toolbar-block img').each(function function_name() {
		$(this).bind({
			'vmousedown': function() {
				$(this).addClass("toolbar-block-mousedown");
			},
			'vmouseup': function() {
				$(this).removeClass("toolbar-block-mousedown");
			}
		})
	})

	//3.工具栏
	//增加文章
	$('#add_article').on('tap', function() {
		window.location.href = 'toolbar/addArticle.html';
	})

	//设置
	$('#settings').on('tap', function() {
		window.location.href = 'toolbar/setting.html';
	})

	//4.侧边栏
	//显示
	$('#aside_toolbar').on('tap', function() {
		$('#mui-backdrop').css('display', 'block')
		$(this).attr('src', 'img/icon/main_menu_negative_normal.png');
		mui('.mui-off-canvas-wrap').offCanvas('show');
	})

	//信息反馈
	$('#feedback').on('tap', function() {
		window.location.href = 'aside/feedback_qq.html';
	})

	//帮助信息

	//关于我们
	$('#about_us').on('tap',function () {
		window.location.href = 'aside/about.html'
	})
	
	//关闭
	$('#hide_aside').on('tap', function() {
		$('#mui-backdrop').css('display', 'none')
		$('#aside_toolbar').attr('src', 'img/icon/main_menu_normal.png');
		mui('.mui-off-canvas-wrap').offCanvas('close');
	})

	//5.主要逻辑
	//javabasic
	$('#javabasic').tap(function() {
		window.location.href = 'list/javabasic_list.html';
	})
	//arithmetic
	$('#arithmetic').on('tap',function () {
		window.location.href = 'list/arithmetic_list.html';
	})
	//java_advance
	$('#java_advance').on('tap',function () {
		window.location.href = 'list/java_advance_list.html';
	})
	//designpattern
	$('#designpattern').on('tap',function () {
		window.location.href = 'list/designpattern_list.html';
	})
	//database
	$('#database').on('tap',function () {
		window.location.href = 'list/database_list.html';
	})
	//javaweb
	$('#javaweb').on('tap',function () {
		window.location.href = 'list/javaweb_list.html';
	})
	//framework
	$('#framework').on('tap',function () {
		window.location.href = 'list/framework_list.html';
	})
	//javaee
	$('#javaee').on('tap',function () {
		window.location.href = 'list/javaee_list.html';
	})
	//javaapi
	$('#javaapi').on('tap',function () {
		window.location.href = 'list/javaapi_list.html';
	})
	//samples
	$('#javasamples').on('tap',function() {
		window.location.href = 'list/designpattern_list.html';
	})
	//interview
	$('#interview').on('tap',function () {
		window.location.href = 'list/interview_list.html';
	})
	//topics
	$('#topics').on('tap',function () {
		window.location.href = 'list/framework_list.html';
	})
	//docedit_large
	$('#docedit_large').on('tap',function () {
		window.location.href = 'list/javaweb_list.html';
	})
	//home_default
	$('#home_default').on('tap',function () {
//		window.open('http://www.bestick.cn','_black')
		mui.openWindow({
			url: 'http://www.bestick.cn',
			id: 'bestick'
		})
	})
})